package fatworm.concept.datatype;
/**
 * data type INT
 */
public class FatInt extends fatworm.concept.DataType{
	private static final FatInt instance = new FatInt();
	public static FatInt getInstance(){
		return instance;
	}

	private FatInt(){}
	public int getTypeKey() {
		return T_INT;
	}
	/**
	 * create a new integer value
	 */
	public IntValue createValue( int value ){
		return new IntValue( value );
	}
	
	public IntValue convert( SqlValue value ) 
			throws ConvertException {
		switch( value.getType().getTypeKey() ){
			case T_INT   : return (IntValue)value;
			case T_STRING: 
				try{
					return createValue( Integer.parseInt( value.toString() ));
				}catch( java.lang.NumberFormatException e ){
					throw new ConvertException( value , this );
				}
			default : throw new ConvertException( value , this );	
		}
	}
	
	public String toString() {
		return "INT";
	}
	
	public class IntValue extends SqlValue{
		public int value;
		private IntValue( int value ){
			this.value = value;
		}
		public String toString() {
			return Integer.toString( value );
		}
	}
}	
